#include "Timer.hpp"

namespace timer {
//////////////////////////////////////////////////////////////////////////
// TODO: Manage LOCK_VARIABLE

Timer::Timer(void (*apFct)(), int aiSpeed) : m_pFunction(apFct), m_iSpeed(aiSpeed)
{
	LOCK_FUNCTION(m_pFunction);
}

Timer::Timer(void (*apFct)(void *), void *apParam, int aiSpeed) : m_pParamFunction(apFct), m_vpParam(apParam), m_iSpeed(aiSpeed)
{
	LOCK_FUNCTION(m_pFunction);
}

Timer::~Timer()
{
	Unregister();
}

bool Timer::Register()
{
	if (m_pFunction)	
		return install_int(m_pFunction, m_iSpeed)==0 ? true : false;
	else if (m_pParamFunction)
		return install_param_int(m_pParamFunction, m_vpParam, m_iSpeed)==0 ? true : false;
	
	return false;
}


bool Timer::Unregister()
{
	if (m_pFunction)	
		remove_int(m_pFunction);
	else if (m_pParamFunction)
		remove_param_int(m_pParamFunction, m_vpParam);

	return true;
}

bool Timer::ChangeSpeed(int aiNewSpeed)
{
	return true;
}

//////////////////////////////////////////////////////////////////////////
} // namespace time
